<!--
 * @Author: sbotlp
 * @Email: sbotlp@sina.com
 * @Date: 2019-11-23 23:47:56
 * @LastEditTime: 2019-11-24 00:31:29
 * @Description: http://www.sbotlp.com.cn
 -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
    Object.defineProperty
    <script>
      const obj1 = {
        name: '张三',
        age:26
      }
      console.log('obj1: ', obj1);
      // 通过  Object.defineProperty 方法 监听对象中属性的变化；
      const obj= {};
      let _name = '张三';
      Object.defineProperty(obj,'name', {
        get:function() {
          // 属性值变化之后，会自动执行，在此刻做监听
          console.log('get', _name); // 监听
          return _name;
        },
        set:function(newValue) {
          console.log('set', newValue); // 监听
          _name = newValue;
        }
      });
    </script>
</body>
</html>